package com.zx.fm.controller;

import com.zx.common.annotation.Log;
import com.zx.common.core.controller.BaseController;
import com.zx.common.core.domain.AjaxResult;
import com.zx.common.core.page.TableDataInfo;
import com.zx.common.enums.BusinessType;
import com.zx.common.utils.poi.ExcelUtil;
import com.zx.fm.domain.GoodsLoanVO;
import com.zx.fm.domain.PaymentApplication;
import com.zx.fm.domain.PaymentApplicationVO;
import com.zx.fm.service.IPaymentApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * -- 高贵的马儿驱逐体内的一切外力 --
 *
 * @author kaajee
 * @date 2025/9/3
 * @desc
 */
@RestController
@RequestMapping("/fm/pa")
public class PaymentApplicationController extends BaseController {
    @Autowired
    private IPaymentApplicationService paymentApplicationService;

    /**
     * 查询付款申请列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PaymentApplicationVO paymentApplicationVO) {
        startPage();
        List<PaymentApplicationVO> list = paymentApplicationService.listAll(paymentApplicationVO);
        return getDataTable(list);
    }
    /**
     * 根据id查询付款申请
     */
    @RequestMapping("/get/{id}")
    public AjaxResult getPayment(@PathVariable Long id) {
        PaymentApplicationVO payment = paymentApplicationService.getPayment(id);
        return AjaxResult.success(payment);
    }
    /**
     * 新增付款申请
     */
    @PreAuthorize("@ss.hasPermi('fm:pa:add')")
    @Log(title = "付款管理", businessType = BusinessType.INSERT)
    @RequestMapping("/add")
    public AjaxResult addPayment(@RequestBody PaymentApplication paymentApplication) {
        paymentApplication.setUserId(getUserId());
        paymentApplication.setApplicationTime(new Date());
        return toAjax(paymentApplicationService.insertPayment(paymentApplication));
    }
    /**
     * 删除付款申请
     */
    @PreAuthorize("@ss.hasPermi('fm:pa:del')")
    @Log(title = "付款管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{id}")
    public AjaxResult delPayment(@PathVariable Long id) {
        return toAjax(paymentApplicationService.deletePayment(id));
    }
    /**
     * 修改付款申请
     */
    @PreAuthorize("@ss.hasPermi('fm:pa:edit')")
    @Log(title = "付款管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult editPayment(@RequestBody PaymentApplication paymentApplication) {
        return toAjax(paymentApplicationService.updatePayment(paymentApplication));
    }
    @PreAuthorize("@ss.hasPermi('fm:pa:export')")
    @Log(title = "付款管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaymentApplicationVO paymentApplicationVO) {
        List<PaymentApplicationVO> list = paymentApplicationService.listAll(paymentApplicationVO);
        ExcelUtil<PaymentApplicationVO> util = new ExcelUtil<>(PaymentApplicationVO.class);
        util.exportExcel(response, list, "付款申请数据");
    }
}
